<!-- +----------------------------------------------------------------------
| 麦沃德科技赋能开发者，助力中小企业发展 
+----------------------------------------------------------------------
| Copyright (c) 2017～2024  www.wdadmin.cn    All rights reserved.
+----------------------------------------------------------------------
| 沃德代驾系统并不是自由软件，不加密，并不代表开源，未经许可不可自由转售和商用
+----------------------------------------------------------------------
| Author: MY WORLD Team <bd@maiwd.cn>   www.wdadmin.cn
+----------------------------------------------------------------------
| 提现审核 开发者: 麦沃德科技-半夏
+---------------------------------------------------------------------- -->

<template>
	<view class="container" v-if="loadEnd">
		<view class="container-list" v-if="amountList.length">
			<view class="list-item" v-for="item in amountList" :key="item.id">
				<view class="item-head flex">
					<view class="head-left flex-item flex align-items-center">
						<view class="left-name text-ellipsis">{{item.title}}</view>
						<text class="left-status" style="color: #FFB500;" v-if="item.state == 1">审核中</text>
						<text class="left-status" style="color: #FA2C3E;" v-else-if="item.state == 3">已驳回</text>
						<text class="left-status" :style="{color: themeColor}" v-else-if="item.state == 2 || item.state == 4">已通过</text>
					</view>
					<view class="head-amount flex">{{item.amount}}<text class="unit">元</text></view>
				</view>
				<view class="item-time">{{item.state == 1 ? item.createtime : item.handle_time}}</view>
				<view class="flex justify-content-end" v-if="item.state == 4">
					<view class="item-btn" :style="{background: themeColor}" @click="handleReceive()">确认收款</view>
				</view>
				<view class="item-tips" v-if="item.state == 3">驳回原因：{{item.reject}}</view>
				<view class="item-mask" v-if="amountLoading">
					<view class="mask-top">
						<view class="top-left"></view>
						<view class="top-right"></view>
					</view>
					<view class="mask-bottom">
						<view class="bottom-box"></view>
					</view>
				</view>
			</view>
		</view>
		<empty top="30%" title="暂无相关内容~" v-else></empty>
	</view>
</template>

<script>
	import { mapState } from "vuex"
	export default {
		data() {
			return {
				// 加载完成
				loadEnd: false,
				// 分类查询参数
				page: 1,
				limit: 20,
				hasMore: false,
				// 明细列表
				amountList: {},
				// 明细是否加载
				amountLoading: false,
			}
		},
		computed: {
			...mapState({
				themeColor: state => state.app.themeColor,
			})
		},
		onLoad() {
			uni.showLoading({
				title: "加载中"
			})
			this.getAmountList(() => {
				uni.hideLoading()
				this.loadEnd = true
			})
		},
		onPullDownRefresh() {
			this.page = 1
			this.amountLoading = true
			this.getAmountList(() => {
				this.amountLoading = false
				uni.stopPullDownRefresh()
			})
		},
		onReachBottom() {
			if (this.hasMore) {
				this.page++
				this.getAmountList()
			}
		},
		methods: {
			// 获取收支明细列表
			getAmountList(fn) {
				this.$util.request("driver.wallet.examineList", {
					page: this.page,
					limit: this.limit,
				}).then(res => {
					if (fn) fn()
					if (res.code == 1) {
						let list = res.data.data
						this.hasMore = this.page < res.data.total / this.limit ? true : false
						this.amountList = this.page == 1 ? list : [...this.amountList, ...list];
					} else {
						uni.showToast({
							title: res.msg,
							icon: 'none'
						})
					}
				}).catch(error => {
					console.error('获取收支明细列表 ', error)
				})
			},
			// 确认收款
			handleReceive() {
				uni.showModal({
					title: "系统提示",
					content: "请前往小程序端确认收款",
					showCancel: false,
					confirmText: "我知道了",
					confirmColor: this.themeColor
				})
			},
		}
	}
</script>

<style lang="scss">
	.container {
		padding: 32rpx;

		.container-list {
			.list-item {
				position: relative;
				padding: 32rpx;
				border-radius: 32rpx;
				background: #FFF;
				margin-top: 32rpx;

				&:first-child {
					margin-top: 0;
				}

				.item-head {
					.head-left {
						.left-name {
							color: #242629;
							font-size: 28rpx;
							font-weight: 600;
							line-height: 40rpx;
						}

						.left-status {
							margin-left: 16rpx;
							font-size: 28rpx;
							font-weight: 600;
							line-height: 40rpx;
						}
					}

					.head-amount {
						color: #242629;
						font-size: 28rpx;
						font-weight: 600;
						line-height: 40rpx;

						.unit {
							margin-left: 16rpx;
						}
					}
				}

				.item-time {
					margin-top: 16rpx;
					color: #8D929C;
					font-size: 24rpx;
					font-weight: 600;
					line-height: 34rpx;
				}

				.item-tips {
					margin-top: 16rpx;
					color: #8D929C;
					font-size: 24rpx;
					font-weight: 600;
					line-height: 34rpx;
				}

				.item-btn {
					margin-top: 20rpx;
					color: #FFF;
					text-align: center;
					font-size: 24rpx;
					font-weight: 600;
					line-height: 64rpx;
					width: 176rpx;
					height: 64rpx;
					border-radius: 24rpx;
				}

				.item-mask {
					position: absolute;
					top: 0;
					left: 0;
					right: 0;
					bottom: 0;
					z-index: 5;
					background: #FFF;
					padding: 40rpx 0;
					display: flex;
					flex-direction: column;
					justify-content: space-between;

					.mask-top {
						display: flex;
						justify-content: space-between;

						.top-left {
							flex: 1;
							height: 40rpx;
							background: #eee;
						}

						.top-right {
							margin-left: 32rpx;
							width: 38%;
							height: 40rpx;
							background: #eee;
						}
					}

					.mask-bottom {
						.bottom-box {
							width: 100%;
							height: 34rpx;
							background: #eee;
						}
					}
				}
			}
		}
	}
</style>